package com.mfnote.adapter;

import java.util.List;

import com.mfnote.util.image.ImageManager;
import com.mfnote.view.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

/**
 * 插入视频列表适配器
 * 
 * @author DC
 * 
 */
public class VideoListAdapter extends BaseAdapter {

	private Context context;
	private List<String> imagesList; // 各个图片的路径

	public VideoListAdapter(Context context, List<String> imagesList) {
		this.context = context;
		this.imagesList = imagesList;
	}

	/** 得到总的数量 **/
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return imagesList.size();
	}

	/** 根据ListView位置返回View **/
	@Override
	public Object getItem(int position) {
		return imagesList.get(position); // 返回当前选中的item图片的路径
	}

	/** 根据ListView位置得到List中的ID **/
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position; // 返回当前选中项的Id
	}

	/** 根据位置得到View对象 **/
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.newwrite_image_item, null);
		}

		ImageView img = (ImageView) convertView
				.findViewById(R.id.newwrite_et_content_image); // 图片列表项

		if (!imagesList.get(position).equals("")) {// 没有图片
			Bitmap tempBitmap = BitmapFactory.decodeFile("/mnt/sdcard/MFNote/notes/"+imagesList
					.get(position));// 根据路径显示对应的图片
			Bitmap newBitmap = new ImageManager(context).zoomBitmap(tempBitmap,
					tempBitmap.getWidth(), tempBitmap.getHeight());
			img.setImageBitmap(newBitmap);// 对应的行上显示对应的图片
		}
		return convertView;
	}

}
